#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = -1, right = 0, n = nums.size(), sum = 0;
        int res = INT_MAX;
        while (right < n)
        {
            while (right < n && sum < target) sum += nums[right++];
            while (left < right && sum >= target) sum -= nums[++left];
            res = min(right - left, res);
        }
        if (res > n) return 0;
        return res;
    }
};